# grammar for ipgen input
# $Id: grammar,v 1.4 2000/06/05 14:40:49 ni Exp $
#
# Terminal symbols are written in uppercase and specified as perl
# regexps below.
#
# Input is line oriented; emtpy lines and comment lines (i. e. lines
# with the first non-whitespace character being a '#') are allowed
# everywhere. Tokens must be separated by whitespace (which includes
# commas in this case), expect NEWLINE, which is whitespace in
# itself.


# An ipgen input file consists of zero of more packet descriptions.

ipgen_input	::= { packet_descr }*

# A packet description is either a default packet description (which
# sets default values for following normal packet descriptions) or a
# normal packet description. Only normal packet description generate
# output. Fields that are not specified in a normal packet description
# are set from the last default packet description specified before.

packet_descr	::= default_packet | normal_packet

# A default or normal packet description consists of an opening
# "default" or "packet" line, the description of the packet contents,
# and a closing "end" line.

default_packet	::= default_line packet_contents end_line
normal_packet	::= packet_line  packet_contents end_line

# The opening packet line consists of the "packet" or "default"
# keyword and the name of the packet (optional for default packet).

packet_line	::= PACKET_KEYWORD NAME NEWLINE
default_line	::= DEFAULT_KEYWORD [NAME] NEWLINE

# The end line contains only the keyword "end".

end_line	::= END_KEYWORD NEWLINE

# The packet contents consists of header and data lines.

packet_contents	::= { header_line | data_line }*

# Header lines consist of a keyword and a value. The value is either
# an IP address in n.n.n.n notation (for ip_src and ip_dest) or an
# arbitrary string (for comment) or a simple numeric field (all
# others)

header_line	::= { ADDR_FIELD ADDR_VALUE NEWLINE }   |
		    { COMMENT_FIELD [COMMENT] NEWLINE } |
		    { NUMERIC_FIELD numeric_value NEWLINE }

# Numeric values may be specified in decimal, octal (with leading
# zero) or hexadecimal (with leading "0x").

numeric_value	::= DECIMAL_VALUE | OCTAL_VALUE | HEX_VALUE

# A data line consists of the "data" keyword and zero or more
# hexadecimal single-byte values with optional leading "0x".

data_line	::= DATA_KEYWORD { DATA_VALUE }* NEWLINE

# Terminal symbols

DEFAULT_KEYWORD	::= "default"

PACKET_KEYWORD	::= "packet"

END_KEYWORD	::= "end"

COMMENT		::= ".*"

NEWLINE		::= "\n"

NUMERIC_FIELD	::= "real_length|ip_v|ip_hl|ip_tos|ip_len|ip_id" | 
		    "ip_flags|ip_off|ip_ttl|ip_p|ip_sum|udp_sport" |
		    "udp_dport|udp_ulen|udp_sum|icmp_type|icmp_code" |
		    "icmp_sum|icmp_unused|icmp_id|icmp_seq"

COMMENT_FIELD	::= "comment"

COMMENT		::= ".*"

DECIMAL_VALUE	::= "[1-9][0-9]*"

OCTAL_VALUE	::= "0[0-9]*"

HEX_VALUE	::= "0[xX][0-9a-fA-F][0-9a-fA-F]*"

ADDR_FIELD	::= "ip_src|ip_dst"

ADDR_VALUE	::= "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"

DATA_KEYWORD	::= "data"

DATA_VALUE	::= "{0[xX]}?[0-9a-fA-F][0-9a-fA-F]"

# EOG
